home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / WINPROGS / UPC12BS1.ZIP / UUCICO / COMMLIB.C < prev    next >
C/C++ Source or Header  |  1993-10-02  |  12KB  |  344 lines

  1. /*--------------------------------------------------------------------*/
  2. /*       c o m m l i b . C                                            */
  3. /*                                                                    */
  4. /*       Generic communications library interface for UUPC/extended.  */
  5. /*--------------------------------------------------------------------*/
  6.  
  7. /*--------------------------------------------------------------------*/
  8. /*    Changes Copyright (c) 1990-1993 by Kendra Electronic            */
  9. /*    Wonderworks.                                                    */
  10. /*                                                                    */
  11. /*    All rights reserved except those explicitly granted by the      */
  12. /*    UUPC/extended license agreement.                                */
  13. /*--------------------------------------------------------------------*/
  14.  
  15. /*--------------------------------------------------------------------*/
  16. /*                          RCS Information                           */
  17. /*--------------------------------------------------------------------*/
  18.  
  19. /*
  20.  *    $Id: commlib.c 1.9 1993/10/02 23:13:29 ahd Exp $
  21.  *
  22.  *    Revision history:
  23.  *    $Log: commlib.c $
  24.  * Revision 1.9  1993/10/02  23:13:29  ahd
  25.  * Allow suppressing TCPIP support
  26.  *
  27.  * Revision 1.8  1993/09/27  00:45:20  ahd
  28.  * Allow named pipes under OS/2 16 bit
  29.  *
  30.  * Revision 1.7  1993/09/24  03:43:27  ahd
  31.  * Add os/2 named pipes
  32.  *
  33.  * Revision 1.6  1993/09/20  04:46:34  ahd
  34.  * OS/2 2.x support (BC++ 1.0 support)
  35.  * TCP/IP support from Dave Watt
  36.  * 't' protocol support
  37.  *
  38.  * Revision 1.5  1993/07/22  23:22:27  ahd
  39.  * First pass at changes for Robert Denny's Windows 3.1 support
  40.  *
  41.  * Revision 1.4  1993/07/13  01:13:32  ahd
  42.  * Don't print NULL communications suite name!
  43.  *
  44.  * Revision 1.3  1993/07/11  14:38:32  ahd
  45.  * Display chosen suite
  46.  *
  47.  * Revision 1.2  1993/05/30  15:25:50  ahd
  48.  * Multiple driver support
  49.  *
  50.  * Revision 1.1  1993/05/30  00:01:47  ahd
  51.  * Initial revision
  52.  *
  53.  */
  54.  
  55. /*--------------------------------------------------------------------*/
  56. /*                        System include files                        */
  57. /*--------------------------------------------------------------------*/
  58.  
  59. #include <stdio.h>
  60. #include <string.h>
  61. #include <time.h>
  62.  
  63. /*--------------------------------------------------------------------*/
  64. /*                       UUPC/extended includes                       */
  65. /*--------------------------------------------------------------------*/
  66.  
  67. #include "lib.h"
  68. #include "hlib.h"
  69. #include "commlib.h"
  70.  
  71. #include "ulib.h"             // Native communications interface
  72.  
  73. #if !defined(BIT32ENV) && !defined(FAMILYAPI) && !defined(_Windows)
  74. #include "ulibfs.h"           // DOS FOSSIL interface
  75. #include "ulib14.h"           // DOS ARTISOFT INT14 interface
  76. #endif
  77.  
  78. /*--------------------------------------------------------------------*/
  79. /*       Use the NOTCPIP to suppress the TCP/IP when you don't        */
  80. /*       have WINSOCK.H                                               */
  81. /*--------------------------------------------------------------------*/
  82.  
  83. #if defined(WIN32) || defined(_Windows)
  84. #ifndef NOTCPIP
  85. #include "ulibip.h"           // Windows sockets on TCP/IP interface
  86. #define TCPIP
  87. #endif
  88. #endif
  89.  
  90. #if defined(__OS2__) || defined(FAMILYAPI)
  91. #include "ulibnmp.h"          // OS/2 named pipes interface
  92. #endif
  93.  
  94. #define NATIVE "internal"
  95.  
  96. /*--------------------------------------------------------------------*/
  97. /*                          Global variables                          */
  98. /*--------------------------------------------------------------------*/
  99.  
  100. boolean portActive;         /* Port active flag for error handler   */
  101. boolean traceEnabled;        // Trace active flag
  102.  
  103. commrefi activeopenlinep, passiveopenlinep, swritep;
  104. commrefu sreadp;
  105. commrefv ssendbrkp, closelinep, SIOSpeedp, flowcontrolp, hangupp;
  106. commrefB GetSpeedp;
  107. commrefb WaitForNetConnectp;
  108. commrefb CDp;
  109.  
  110. /*--------------------------------------------------------------------*/
  111. /*                          Local variables                           */
  112. /*--------------------------------------------------------------------*/
  113.  
  114. static FILE *traceStream;    // Stream used for trace file
  115.  
  116. static short   traceMode;    // Flag for last data (input/output)
  117.                              // written to trace log
  118.  
  119. static boolean network = FALSE;  // Current communications suite is
  120.                                  // network oriented
  121.  
  122. currentfile();
  123.  
  124. /*--------------------------------------------------------------------*/
  125. /*       c h o o s e C o m m u n i c a t i o n s                      */
  126. /*                                                                    */
  127. /*       Choose communications suite to use                           */
  128. /*--------------------------------------------------------------------*/
  129.  
  130. boolean chooseCommunications( const char *name )
  131. {
  132.    static COMMSUITE suite[] =
  133.    {
  134.         { NATIVE,                      // Default for any opsys
  135.           nopenline, nopenline, nsread, nswrite,
  136.           nssendbrk, ncloseline, nSIOSpeed, nflowcontrol, nhangup,
  137.           nGetSpeed,
  138.           nCD,
  139.           (commrefb) NULL,
  140.           FALSE
  141.         },
  142. #if !defined(BIT32ENV) && !defined(_Windows) && !defined(FAMILYAPI)
  143.         { "fossil",                    // MS-DOS FOSSIL driver
  144.           fopenline, fopenline, fsread, fswrite,
  145.           fssendbrk, fcloseline, fSIOSpeed, fflowcontrol, fhangup,
  146.           fGetSpeed,
  147.           fCD,
  148.           (commrefb) NULL,
  149.           FALSE
  150.         },
  151.         { "articomm",                  // MS-DOS ARTISOFT INT14 driver
  152.           iopenline, iopenline, isread, iswrite,
  153.           issendbrk, icloseline, iSIOSpeed, iflowcontrol, ihangup,
  154.           iGetSpeed,
  155.           iCD,
  156.           (commrefb) NULL,
  157.           FALSE
  158.         },
  159. #endif
  160.  
  161. #if defined(TCPIP)
  162.         { "tcp/ip",                    // Win32 TCP/IP Winsock interface
  163.           tactiveopenline, tpassiveopenline, tsread, tswrite,
  164.           tssendbrk, tcloseline, tSIOSpeed, tflowcontrol, thangup,
  165.           tGetSpeed,
  166.           tCD,
  167.           tWaitForNetConnect,
  168.           TRUE
  169.         },
  170. #endif
  171.  
  172. #if defined(__OS2__) || defined(FAMILYAPI)
  173.         { "namedpipes",                // OS/2 named pipes
  174.           pactiveopenline, ppassiveopenline, psread, pswrite,
  175.           pssendbrk, pcloseline, pSIOSpeed, pflowcontrol, phangup,
  176.           pGetSpeed,
  177.           pCD,
  178.           pWaitForNetConnect,
  179.           TRUE
  180.         },
  181. #endif
  182.         { NULL }                       // End of list
  183.    };
  184.  
  185.    int subscript = 0;
  186.  
  187. /*--------------------------------------------------------------------*/
  188. /*                   Search for name in suite table                   */
  189. /*--------------------------------------------------------------------*/
  190.  
  191.    while (( name  != NULL ) && (suite[subscript].type != NULL ))
  192.    {
  193.       if ( equali(name,suite[subscript].type))
  194.          break;                           // Success!
  195.       else
  196.          subscript++;
  197.    } /* while */
  198.  
  199.    if ( suite[subscript].type == NULL )
  200.    {
  201.       printmsg(0,"chooseCommunications: Invalid suite name %s",
  202.                   name );
  203.       return FALSE;
  204.    }
  205.  
  206. /*--------------------------------------------------------------------*/
  207. /*       We have a valid suite, define the routines to use and        */
  208. /*       return to caller                                             */
  209. /*--------------------------------------------------------------------*/
  210.  
  211.    activeopenlinep    = suite[subscript].activeopenline;
  212.    passiveopenlinep   = suite[subscript].passiveopenline;
  213.    sreadp             = suite[subscript].sread;
  214.    swritep            = suite[subscript].swrite;
  215.    ssendbrkp          = suite[subscript].ssendbrk;
  216.    closelinep         = suite[subscript].closeline;
  217.    SIOSpeedp          = suite[subscript].SIOSpeed;
  218.    flowcontrolp       = suite[subscript].flowcontrol;
  219.    hangupp            = suite[subscript].hangup;
  220.    GetSpeedp          = suite[subscript].GetSpeed